﻿namespace WeChat.AspNet
{
    /// <summary>
    /// 响应的文本消息类。
    /// </summary>
    public class TextMsg : ResMsg
    {
        /// <summary>
        /// 文本消息类模版。
        /// </summary>
        private const string Template = @"<xml>
  <ToUserName><![CDATA[{0}]]></ToUserName>
  <FromUserName><![CDATA[{1}]]></FromUserName>
  <CreateTime>{2}</CreateTime>
  <MsgType><![CDATA[{3}]]></MsgType>
  <Content><![CDATA[{4}]]></Content>
</xml>";

        public TextMsg(string fromUserName, string toUserName) : base(fromUserName, toUserName)
        {
        }
        /// <summary>
        /// 文本内容。
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 消息类型为文本。
        /// </summary>
        public override ResMsgType MsgType
        {
            get
            {
                return ResMsgType.Text;
            }
        }
        /// <summary>
        /// 把文本对象转化成微信可识别的xml
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var xmlContent = string.Format(Template, ToUserName, FromUserName, CreateTime, MsgType, Content);
            return xmlContent;
        }
    }
}